import Vue from 'vue'
import VueRouter from 'vue-router'
import films from '@/views/Films.vue' //引入Films.vue
import cinemas from '../views/Cinemas' //.vue可以省略
import comingsoon from '@/views/films/Comingsoon.vue'
import more from '@/views/films/More.vue'
import search from '@/views/cinemas/Search.vue'
import city from '@/views//cinemas/City.vue'
import myself from '@/views/Myself.vue'
import nowplaying from '@/views/films/Nowplaying.vue'

Vue.use(VueRouter)// 注册路由插件 
// 注册路由插件的同时也会同时全局安装 router-view和router-link

const routes = [
  {
    path:'/films',
    component:films,
    children:[
      {
        path:'/films/comingsoon',
        component:comingsoon
      },
      {
        path:'/films/nowplaying',
        component:nowplaying
      },
      {
        path:'/films',
        redirect:'/films/nowplaying'
      }
    ]
  },
  {
    path:'/myself',
    component:myself
  },
  {
    // 通过name链接
    name:'lth',
    path:'/more/:myid',
    component:more
  },
  {
    path:'/cinemas',
    component:cinemas
  },
  {
    path:'/search',
    component:search,
  },
  // 重定向
  {
    path:'*',
    redirect:'/films'
  },
  {
    path:'/city',
    component:city
  }
  
]
const router = new VueRouter({
  routes,
  mode:'hash'
})



// 路由拦截器
// router.beforeEach((to,from,next)=>{
//   if(to.meta.islth){
//     if(localStorage.getItem("lth")){
//       next()
//     }else{
//       next({
//         path:'/login',
//         query:{redirect: to.fullPath}
//       })
//     }
//   }else{
//     next()
//   }
// })

export default router
